﻿CREATE TABLE [dbo].Insurer(

	[Id] [dbo].[Id] NOT NULL IDENTITY(1000000000, 1), 
	
    [EntityId] [dbo].[Id] NOT NULL, 
	
    [InsurerType] [dbo].[EnumerationValue] NOT NULL DEFAULT 0, 
	
    [NationalPlanId] [dbo].[BusinessId] NOT NULL, 
	
    [CreateId] [dbo].[Name] NOT NULL DEFAULT SUSER_NAME () , 

    [CreateDateTime] [dbo].[CreateModifiedDateTime] NOT NULL DEFAULT GETDATE() , 

    [ModifiedId] [dbo].[Name] NOT NULL DEFAULT SUSER_NAME (),

    [ModifiedDateTime] [dbo].[CreateModifiedDateTime] NOT NULL DEFAULT GETDATE(), 

    CONSTRAINT [PK_Insurer] PRIMARY KEY ([Id]),
	
	CONSTRAINT [UNQ_Insurer_InsurerTypeNationalPlanId] UNIQUE (InsurerType, NationalPlanId), 

    CONSTRAINT [FK_Insurer_EntityId] FOREIGN KEY (EntityId) REFERENCES Entity(Id)

)

GO

CREATE INDEX [IDX_Insurer_NationalPlanId] ON [dbo].Insurer (NationalPlanId)

GO